// components/topInfo/index.js
let {
  getHotInfo,
  getSinggerTop,
  getMIc
} = require("../../utils/request")
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    topid: Number,
    singgerid:Number,
    // searchId:Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: []
  },
  lifetimes: {
    // async attached(){
    //   let res = await getHotInfo(this.data.topid)
    //   console.log(res);

    // }
  },
  observers: {
    // 箭头函数没有this指向
    "topid": async function (a) {
      console.log(a);
      if (a == 0) {
        // 表示初始化，不发送请求
        return
      }
      let res = await getHotInfo(a)
      console.log(res.data);
      wx.setNavigationBarTitle({
        title: res.data.playlist.name
      })
      this.setData({
        list: res.data.playlist.tracks
      })
    },
    "singgerid":async function(a){
      console.log(a);
      if(a==0){
        return
      }
      let res = await getSinggerTop(a);
      console.log(res);
      this.setData({
        list: res.data.songs
      })
    },
    // "searchId":async function(a){
    //   console.log(a);
    //   if(a==0){
    //     return
    //   }
    //   let res = await getMIc(a);
    //   console.log(res);
    //   this.setData({
    //     list: res.data.songs
    //   })
    // }

  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 去播放
    goPlayer(e) {
      // 获取点击的id值
      console.log(e.currentTarget.dataset.playindex);
      let playIndex = e.currentTarget.dataset.playindex
      

      // 跳转去播放走之前，将当前播放的列表存放在本地
      wx.setStorage({
        key: 'playList',
        data: this.data.list,
        success() {
          wx.reLaunch({
            url: '/pages/palying/playing?playIndex='+playIndex,
          })
        }
      })
     

    },
    // 随机播放跳转
    goPlaying(){
      console.log(123);
      wx.setStorage({
        key:"playList",
        data:this.data.list,
        success(){
          wx.reLaunch({
            url: '/pages/palying/playing?isRandom='+true,
          })
        }
      })
    }
  }
})